// album.js
const sketch = require('../../utils/sketch.js')
Page({
  data: {
    imagePath: '',
    sketchImagePath: ''
  },
  chooseImage: function () {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album'],
      success: (res) => {
        const tempFilePaths = res.tempFilePaths
        this.setData({
          imagePath: tempFilePaths[0]
        })
        this.processImage(tempFilePaths[0])
      }
    })
  },
  processImage: function (imagePath) {
    // 这里应该调用素描算法
    // 为了演示，我们只是简单地将图片转换为灰度
    sketch.convertToSketch(imagePath).then(sketchPath => {
      this.setData({
        sketchImagePath: sketchPath
      })
    })
  },
  saveImage: function () {
    wx.saveImageToPhotosAlbum({
      filePath: this.data.sketchImagePath,
      success: (res) => {
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },
  backToHome: function () {
    wx.navigateBack()
  }
})
